#include "huffman_tree.h"

int main() {
    char ch;
    char buf[24];
    memset(buf, '\0', sizeof(buf));
    Huffman_Tree p = NULL;
    ShowInstructions();
    while (1) {
        memset(buf, '\0', sizeof(buf));
        scanf("%s", buf);
        ch = buf[0];
        if (buf[1] == '\0')
            switch (ch) {
                case 'i':
                    p = init_huffman_tree(p);
                    break;
                case 's':
                    save_tree(p);
                    break;
                case 'l':
                    p = load_tree();
                    break;
                case 'v':
                    show_huffman_tree(p, -1, 0);
                    break;
                case 'd':
                    Decode(p);
                    break;
                case 'e':
                    Encode(p);
                    break;
                case 'f':
                    free_tree(p);
                    p = NULL;
                    break;
                case 'h':
                    ShowInstructions();
                    break;
                case EOF:
                case 'q':
                    printf("Program Exit\n");
                    exit(0);
                default:
                    printf("Undefined Operation! Use h get help\n");
                    break;
            }
        else
            printf("Please input one char per line!\n");
    }
}
